﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Data;
using System.IO;
using System.Windows.Media.Imaging;
using DataBasetestApp.ServiceReference2;
using Microsoft.Samples.WindowsPhoneCloud.StorageClient;

namespace DataBasetestApp.Views
{
    public partial class MatchDetails : PhoneApplicationPage
    {
        public MatchDetails()
        {
            InitializeComponent();
        }

        // Set up variables
        public string ID, homeTeam, AwayTeam, Location, Competition, Time, Score, UserID;
        public int user_id;

        //Code to run when navigating to this page
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            //remove the data that was passed to this page by the querystring
            if (NavigationContext.QueryString.TryGetValue("ID", out ID))
            {
                textBlock1.Text = ID;
            }
            if (NavigationContext.QueryString.TryGetValue("HomeTeam", out homeTeam))
            {
                textBlock3.Text = homeTeam;
            }
            if (NavigationContext.QueryString.TryGetValue("Score", out Score))
            {
                textBlock4.Text = Score;
            }
            if (NavigationContext.QueryString.TryGetValue("AwayTeam", out AwayTeam))
            {
                textBlock5.Text = AwayTeam;
            }
            if (NavigationContext.QueryString.TryGetValue("Time", out Time))
            {
                textBlock6.Text = Time;
            }
            if (NavigationContext.QueryString.TryGetValue("Competition", out Competition))
            {
                textBlock8.Text = Competition;
            }
            if (NavigationContext.QueryString.TryGetValue("Location", out Location))
            {
                textBlock10.Text = Location;
            }
            if (NavigationContext.QueryString.TryGetValue("UserID", out UserID))
            {
                // Code to request username of teh reporter
                int temp = Convert.ToInt32(UserID);
                GAALiveServiceClient client = new GAALiveServiceClient();
                client.GetuserNameCompleted +=
                            new EventHandler<GetuserNameCompletedEventArgs>(client_GetuserNameCompleted);
                client.GetuserNameAsync(temp);
            }

            // Set image to source of image box
            image.Source = new BitmapImage(new Uri("http://gaalive.blob.core.windows.net/pics1/" + ID, UriKind.Absolute));
        }

        void client_GetuserNameCompleted(object sender, GetuserNameCompletedEventArgs c)
        {
            textBlock14.Text = c.Result;
        }

        void client_GetImageByIDCompleted(object sender, GetImageByIDCompletedEventArgs s)
        {
            if (s.Error == null)
            {
                //image1.DataContext = s.Result;
            }
        }
    }
}